package ui 
{
	import data.*;
	import events.GCEvent;
	import ui.textfield.GCStylizedText;
	import ui.textfield.GCTextField;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	/**
	 * For use primarily in the trade post menu, button represents
	 * a building that can be or has already been constructed in a 
	 * city.
	 * @author Roy
	 */
	public class GCBuildingButton extends Sprite 
	{
		
		/*
		 * Remember a small amount of information of the
		 * building attached to this button
		 */
		private var _buildingId:int;
		
		private var _imageHolder:Sprite;
		private var _buildingText:GCStylizedText;
		
		// Can we build this thing?
		private var _allowedToBuild:Boolean;
		private var _alreadyBuiltImage:Sprite;
		
		/**
		 * 
		 * 
		 */
		public function GCBuildingButton(id:int, x:int = 0, y:int = 0 ) 
		{
			this.x = x;
			this.y = y;
			
			_buildingId = id;
			_imageHolder = new Sprite();
			_buildingText = new GCStylizedText();
			_allowedToBuild = true;
			_alreadyBuiltImage = new Sprite();
			
			init();
		}

		/**
		 * Get the id of the building the button represents.
		 * 
		 * @return
		 */
		public function getBuildingId():int
		{
			return _buildingId;
		}
		
		public function isEnabled():Boolean
		{
			return _allowedToBuild;
		}
		
		public function setDisabled():void
		{
			_allowedToBuild = false;
			_alreadyBuiltImage.graphics.beginFill(GCConstants.COLOR_WHITE, 0.3)
			_alreadyBuiltImage.graphics.drawRect(0, 0, _imageHolder.width, _imageHolder.height);
			
			var text:GCTextField = new GCTextField();
			text.text = "Already Constructed";
			_alreadyBuiltImage.addChild(text);
			_imageHolder.addChild(_alreadyBuiltImage);
		}
		
		private function init():void
		{
			_buildingText.text = GCBuildingData.getNameFromId(_buildingId);
		
			_imageHolder.addChild(GCResources.getResource(GCBuildingData.getNameFromId(_buildingId)));
			_buildingText.setBgStyle(GCStylizedText.STYLE_TWO, _imageHolder.width, 30);
			_buildingText.y = _imageHolder.y + _imageHolder.height;
			
			this.addChild(_imageHolder);
			this.addChild(_buildingText);
			this.buttonMode = true;
			_imageHolder.buttonMode = true;
		}
		
	}

}